package bookstudytest.stream;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.beans.Encoder;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @Auther: Lee
 * @Date: 2018/6/21 12:00
 * @Description:
 */
public class InputStreamTest {
    public static void main(String[] args) throws IOException {
        URL baidu = new URL("https://www.baidu.com");
        InputStream inputStream = baidu.openStream();
        byte[] a = new byte[9099];
        StringBuilder sb = new StringBuilder();
//        InputStreamReader isr = new InputStreamReader(inputStream, "GBK");
//        BufferedReader bufferedReader = new BufferedReader(isr);
        BufferedInputStream bis = new BufferedInputStream(inputStream);
//        BASE64Decoder decoder = new BASE64Decoder();
//        byte[] bytes = decoder.decodeBuffer(inputStream);
        while (bis.read() != -1) {
            bis.read(a);
            String x = new String(a, "UTF-8");
            sb.append(x);
        }

        System.out.println(sb);
//        String read = bufferedReader.readLine();
//        while (read!=null){
//            System.out.println(read);
//            read = bufferedReader.readLine();
//        }
//
//        bufferedReader.close();
//        isr.close();

        inputStream.close();

    }
}
